package com.domi.controller;

import com.domi.bean.RestfulResponse;
import com.domi.bean.RestfulResponse.ResponseCode;
import com.domi.service.BookService;
import com.domi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/rent")
public class RentController {

    @Autowired
    private BookService bookService;

    @Autowired
    private UserService userService;

    @GetMapping("/order/{bookId}/{userId}")
    public RestfulResponse order(@PathVariable Integer bookId, @PathVariable Integer userId) {
        RestfulResponse bookInfo = bookService.info(bookId);
        RestfulResponse userInfo = userService.info(userId);
        String bookName = ((Map<?, ?>) bookInfo.getData()).get("name").toString();
        String userName = ((Map<?, ?>) userInfo.getData()).get("username").toString();
        return RestfulResponse.create(ResponseCode.SUCCESS, "下单成功，订单信息 ---> 用户: " + userName + ", 书名: " + bookName);
    }

}